//
//  RJWarningFirstView.m
//  AirQuality
//
//  Created by Po on 15/4/9.
//  Copyright (c) 2015年 Po. All rights reserved.
//

#import "RJWarningFirstView.h"
#import "RJWarningFirstDay.h"
#import "RJWarningFirstPicker.h"
#import "RJTools.h"
@interface RJWarningFirstView () <RJWarningFatherDeleaget, WarningFirstDayDelegate>

@property (retain, nonatomic) RJWarningFirstPicker * pickeView;

@property (retain, nonatomic) NSArray * selectArray;
@property (retain, nonatomic) NSMutableArray * daysArray;

- (void)initInterface;
@end

@implementation RJWarningFirstView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {

        [self initInterface];
        [self setFatherDelegate:self];
    }
    return self;
}

- (void)initInterface
{
    _daysArray = [[NSMutableArray alloc] init];
    NSUInteger dayCount = 1;
    for (NSUInteger i = 0; i < 3 ; i ++) {
        RJWarningFirstDay * day = [[RJWarningFirstDay alloc] initWithFrame:CGRectMake(0, 160 *  i, ScreenWidth, 140)];
        [day.timeLabel setText:[RJTools getTimeWithFormat:@"MM月dd日" time:GetFutureSinceNow(dayCount)]];
        [day setDelegate:self];
        [self addSubview:day];
        [_daysArray addObject:day];
        dayCount ++;
    }
}


#pragma mark - RJWarningFatherDeleaget
- (void)WarningFatherSetData:(NSArray *)data
{
    BOOL isDone = [RJUserData defaultRJUserData].isDone;
    BOOL isHistory = [RJUserData defaultRJUserData].isHistory;
    
    NSArray * hourValue = data[0];
    for (NSUInteger i = 0; i < _daysArray.count ; i ++) {
        RJWarningFirstDay * day = _daysArray[i];
        [day.value48 setText:hourValue[i][0]];
        [day.value72 setText:hourValue[i][1]];
        [day.value96 setText:hourValue[i][2]];
        if (isDone || isHistory) {
            [day.selectLabel setText:data[1][i]];
            [day.selectLabel setBackgroundColor:[UIColor clearColor]];
        }
    }
}

- (void)WarningFatherSetUserData:(NSDictionary *)data
{
    NSArray * firstPollutions = data[@"primaryPollutant"];
    for (NSUInteger i = 0; i < _daysArray.count; i ++) {
        RJWarningFirstDay * day = _daysArray[i];
        if (firstPollutions && firstPollutions[i]) {
            if (![firstPollutions[i] isEqualToString:@"点击选择"] && ![firstPollutions[i] isEqualToString:@""]) {
                day.selectLabel.text = firstPollutions[i];
                [day.selectLabel setBackgroundColor:[UIColor clearColor]];
            } else {
                day.selectLabel.text = @"点击选择";
                [day.selectLabel setBackgroundColor:day.selectBackColor];
            }
        }
    }
}

- (void)WarningFatherWillRemoveSelf
{
}

- (NSDictionary *)WarningFatherGetData
{
    NSMutableArray * firstPollutions = [NSMutableArray array];
    for (RJWarningFirstDay * day in _daysArray) {
        NSString * string = day.selectLabel.text;
        if ([string isEqualToString:@"点击选择"]) {
            string = @"";
        }
        [firstPollutions addObject:string];
    }
    return @{@"primaryPollutant":firstPollutions};
}

#pragma mark - WarningFirstDayDelegate
- (void)WarningFirstDay:(RJWarningFirstDay *)day pressSelectString:(NSString *)text
{
    
}














@end
